<div class="form">
<?php
	Yii::app()->clientScript->registerScriptFile(Yii::app()->theme->baseUrl . "/js/jquery.number_format.js", CClientScript::POS_END);

	$form=$this->beginWidget('CActiveForm', array(
	'id'=>'products-form',
	'enableAjaxValidation'=>false,
    'htmlOptions' => array('enctype' => 'multipart/form-data')
)); ?>
	<div class="row buttons" align="right">
		<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
	</div>
	<p class="note">Fields with <span class="required">*</span> are required.</p>

	<?php echo $form->errorSummary($model); ?>

	<div class="row">
        <?php echo $form->labelEx($model, 'category_id'); ?>
        <?php echo $form->dropDownList($model, 'category_id', CHtml::listData(Categories::model()->findAll(array("condition" => "status !='3'")), 'id', 'name')); ?>
        <?php echo $form->error($model, 'category_id'); ?>
    </div>

	<div class="row">
		<?php echo $form->labelEx($model,'name'); ?>
		<?php echo $form->textField($model,'name',array('size'=>60,'maxlength'=>255)); ?>
		<?php echo $form->error($model,'name'); ?>
	</div>

	<div class="row">
        <?php echo $form->labelEx($model, 'price'); ?>
        <?php
        echo $form->textField($model, 'price', array(
            'onkeyup' => '
                var format_number = $().number_format($(this).val().replace(/[^0-9]/g, ""), {
                    numberOfDecimals:0,
                    decimalSeparator: ",",
                    thousandSeparator: " "
                });
                $(this).val(format_number);
            ',
            'value' => number_format($model->price, 0, ' ', ' '),
        ));
        ?>
        <?php echo $form->error($model, 'price'); ?>
    </div>
	<div class="row">
		<?php echo $form->labelEx($model,'image'); ?>
		<?php echo $form->fileField($model,'image',array()); ?>
		<?php echo $form->error($model,'image'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'thumb'); ?>
		<?php echo $form->fileField($model,'thumb',array()); ?>
		<?php echo $form->error($model,'thumb'); ?>
	</div>
	<div class="row">
		<?php echo $form->labelEx($model,'short_descript'); ?>
                <?php
                    $this->widget('application.extensions.tinymce.ETinyMce', array(
                        'id' 		=> 'Products_short_descript',
                    	'model' 	=> $model,
                        'name' 		=> 'Products[short_descript]',
                        'options' 	=> array(
                             'theme' => "advanced",
                    		 'width' => '51%',
                    		 'height' => 100,
							 'theme_advanced_toolbar_location' 	=> "top",
                     		 'theme_advanced_toolbar_align' 	=> 'left',
							 'theme_advanced_buttons1' 			=> "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,|,undo,redo,|,cleanup",
							 'theme_advanced_buttons2' 			=> "",
							 'theme_advanced_buttons3' 			=> ""
                        ),
                        'value' => $model->short_descript
                    ));
                ?>
		<?php echo $form->error($model,'short_descript'); ?>
	</div>
	<div class="row">
		<?php echo $form->labelEx($model,'description'); ?>
                <?php
                    $this->widget('application.extensions.tinymce.ETinyMce', array(
                        'id' 		=> 'Products_description',
                        'name' 		=> 'Products[description]',
                        'model' 	=> $model,
                    	'plugins' => array('jbimages','advimage'),
                    	'options' 	=> array(
                            'theme' 							=> 'advanced',
                            'theme_advanced_toolbar_location' 	=> 'top',
                            'theme_advanced_buttons1' 			=> 'newdocument,|,bold,italic,underline,|,justifyleft,justifycenter,justifyright,fontselect,fontsizeselect,formatselect',
                            'theme_advanced_buttons2' 			=> 'jbimages, | cut,copy,paste,|,bullist,numlist,|,outdent,indent,|,undo,redo,|,link,unlink,anchor,image,|,code,preview,|,forecolor,backcolor',
                            'theme_advanced_buttons3' 			=> '',
                            'theme_advanced_toolbar_align' 		=> 'left'
                        ),
                        'value' => $model->description
                    ));
                ?>
		<?php echo $form->error($model,'description'); ?>
	</div>

	 <div>
        <?php echo $form->labelEx($model, 'promote'); ?>
		<?php echo $form->dropdownlist($model, 'promote', Util::$arrayCofirm) ?>
        <?php echo $form->error($model, 'promote'); ?>
    </div>

	<div class="row">
		<?php echo $form->labelEx($model,'status'); ?>
		<?php echo $form->dropDownList($model,'status', Util::$arrayActive); ?>
		<?php echo $form->error($model,'status'); ?>
	</div>
	<div class="row" >
        <a id="show-hide-upload-block" href="javascript:void(0)"><?php echo Util::t("Upload More Images"); ?></a>
        <div id="upload-block" style="display: none">
            <?php
                $this->widget('application.components.AjaxUploadImagesWidget', array(
                    'defaultUploadFields' => 3
                ));
            ?>
        </div>
    </div>
        <?php if (!$model->isNewRecord): ?>
            <input type="hidden" name="update_id" value="<?php echo $model->id; ?>"/>
        <?php endif; ?>

	<div class="row buttons" align="right">
		<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
	</div>

<?php $this->endWidget(); ?>

</div><!-- form -->